package com.xinou.daily_report.controller;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.xinou.common.base.config.ApiResponse;
import com.xinou.common.base.exception.BusException;
import com.xinou.daily_report.PO.ConfigChangePO;
import com.xinou.daily_report.enumerate.SysConfigEnum;
import com.xinou.daily_report.utils.ConstUtil;
import com.xinou.daily_report.utils.DailyShiroUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lcc
 * @create 2021-07-09
 * @注意 本内容仅限于xinou内部传阅，禁止外泄以及用于其他的商业目的
 */
@RestController
@RequestMapping("/admin/config")
@Api(tags = {"后台 配置"})
public class SysConfigController {

    @PostMapping("list")
    @ApiOperation("获取配置列表")
    @RequiresPermissions({"admin:config:list"})
    public ApiResponse<SysConfigEnum> configList(){
        return new ApiResponse<>(ConstUtil.getMap());
    }

    @PostMapping("set")
    @ApiOperation("set配置")
    @RequiresPermissions({"admin:config:set"})
    public ApiResponse<Void> configSet(){
        ConstUtil.set();
        return new ApiResponse<>();
    }

    @PostMapping("update")
    @ApiOperation("修改配置")
    @RequiresPermissions({"admin:config:update"})
    public ApiResponse<Void> configUpdate(@RequestBody ConfigChangePO po){
        if(!DailyShiroUtil.isBigLead()){
            throw new BusException("权限不足，无法修改");
        }
        ConstUtil.restLeadRole(po);
        return new ApiResponse<>();
    }
}
